/**
 * Created by renzhiqiang on 17/6/26.
 */
var webpack = require('webpack');
var path = require('path');
var commonsPlugin = new webpack.optimize.CommonsChunkPlugin({
    name:["chunk"]
});
var HtmlWebpackPlugin = require('html-webpack-plugin');
const extractTextPlugin = require("extract-text-webpack-plugin");

var autoprefixer = require('autoprefixer');
module.exports = {

    //页面入口文件配置
    entry: {
        "index":'./src/index.js',
        "chunk": ["./src/indexOne.js", "./src/indexTwo.js","./src/jquery-3.1.1.js"]
        // "indexOne":'./src/indexOne.js'
        // "vendor": ['./src/jquery-3.1.1.js']
     } ,
    //入口文件输出配置
    output: {
        path: __dirname + "/dist",
        filename: "[name].js",
        chunkFilename:"[name]-[name].js"
    },
    module: {
        //加载器配置
        loaders: [
            // { test: /\.css$/,loaders:['style-loader','css-loader','postcss-loader']},
            { test: /\.css$/,loader: extractTextPlugin.extract({ fallback: 'style-loader', use: 'css-loader'})},
            {test: /\.js$/, loader: 'babel-loader', exclude: '/node_modules/'},
            { test: /\.scss$/, loader: 'style!css!sass?sourceMap'},
            { test: /\.(png|jpg)$/, loader: 'url-loader?limit=1118192'}
        ]
    },

    //其它解决方案配置
    resolve: {
        extensions: ['.js', '.json', '.scss']
    },
    //插件项
    plugins: [
        new HtmlWebpackPlugin({
            title: 'Custom template',
            filename: __dirname+'/dist/index.html',
            template:__dirname+'/index.html',
            inject:'body',
            hash:true,
            chunks:['chunk','index']
        }),
        new HtmlWebpackPlugin({
            title: 'Custom template',
            filename: __dirname+'/dist/indexOne.html',
            template:__dirname+'/index.html',
            inject:'body',
            hash:true,
            chunks:['chunk','index']
        }),
        commonsPlugin,
        new extractTextPlugin("[name].css"),
        // new webpack.LoaderOptionsPlugin({ //浏览器加前缀
        //     options: {
        //         postcss: [require('autoprefixer')({browsers:['last 5 versions']})]
        //     }
        // })
    ]
};